from django.db import models
from course.models import Course

# Create your models here.


##单词分组模型
class WordGroup(models.Model):
    id = models.BigIntegerField(primary_key=True)
    word_bank_id = models.BigIntegerField()
    name = models.CharField(max_length=20, blank=True, null=True)
    story_audio = models.CharField(max_length=50, blank=True, null=True)
    audio_time = models.DecimalField(max_digits=10, decimal_places=4, blank=True, null=True)
    image_name = models.CharField(max_length=50, blank=True, null=True)
    part_no = models.IntegerField(blank=True, null=True)
    sort_no = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'word_group'
        ordering = ["word_bank_id","part_no","sort_no"]
        verbose_name_plural = "词库分组"

    def __str__(self):
        return str(self.id)



##单词模型
class Word(models.Model):
    id = models.BigIntegerField(primary_key=True)
    name = models.CharField(max_length=30, blank=True, null=True)
    translate = models.CharField(max_length=40, blank=True, null=True)
    phonetic = models.CharField(max_length=40, blank=True, null=True)
    pos = models.CharField(max_length=30, blank=True, null=True)
    syllable = models.CharField(max_length=40, blank=True, null=True)
    word_bank_id = models.BigIntegerField()
    # word_bank = models.ForeignKey(Course,to_field = "word_bank_id")
    part_no = models.IntegerField(blank=True, null=True)
    # word_group_id = models.BigIntegerField(blank=True, null=True)
    word_group = models.ForeignKey(WordGroup)
    sort_no = models.IntegerField(blank=True, null=True)
    word_audio_name = models.CharField(max_length=50, blank=True, null=True)
    spell_audio_name = models.CharField(max_length=50, blank=True, null=True)
    word_audio_time = models.DecimalField(max_digits=10, decimal_places=4, blank=True, null=True)
    spell_audio_time = models.DecimalField(max_digits=10, decimal_places=4, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'word'
        verbose_name_plural = '单词'

    def __str__(self):
        return self.name

##单词音标模型
class WordSpell(models.Model):
    id = models.BigAutoField(primary_key=True)
    # word_id = models.BigIntegerField()
    word = models.ForeignKey(Word)
    symbol = models.CharField(max_length=20, blank=True, null=True)
    sort_no = models.CharField(max_length=10, blank=True, null=True)
    audio_name = models.CharField(max_length=20, blank=True, null=True)
    symbol_point = models.CharField(max_length=20, blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'word_spell'
        verbose_name_plural = '拼写'

    def __str__(self):
        return str(self.word)
